package com.collabscm.md.base.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityResult;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.SqlResultSetMappings;
import javax.persistence.Table;
import com.collabscm.pf.model.DomainObject;

/**
 * 系统用户
 * 
 * @author Zeng Raoxing
 */
@Entity
@Table(name = "t_md_user")

@NamedNativeQueries ({
	//查询系统定义的常量值
	@NamedNativeQuery(name=User.FIND_ENABLE_USER_NAME, 
			query="select * from t_md_user where Account_No = :accountNo and Password = :password and Status = :status" ,
			resultSetMapping="userMapping")
})

//系统常量返回后的映射
@SqlResultSetMappings ({
	@SqlResultSetMapping (
		name="userMapping",
		entities={
			@EntityResult(
				entityClass=User.class 
			)
		}
	)
})
public class User extends DomainObject {
	
	private static final long serialVersionUID = 1L;
	/** 人员ID，引用Person对象的ID */
	private Long personId;
	/** 对应Person对象 */
//	private Person person;
	/** 登录账号 */
	private String accountNo;
	/** 人员姓名 */
	private String personName;
	/** 用户的密码 */
	private String password;
	/** 用户类型*/
	private Long userCategory;
	
	/**
	 * 根据用户名和密码查询有效的用户，用于初始化系统中的业务常量
	 */
	public static final String FIND_ENABLE_USER_NAME = "User.findEnableUser";

	@Id
	@Column(name = "Person_ID", unique = true, nullable = false, precision = 12, scale = 0)
	public Long getPersonId() {
		//此主键是设置的，需要新产生。
		return this.personId;
	}

	public void setPersonId(Long personId) {
		this.personId = personId;
	}

//	@ManyToOne(fetch = FetchType.LAZY)
//	@JoinColumn(name = "Person_ID", unique = true, nullable = false, insertable = false, updatable = false)
//	public Person getPerson() {
//		return this.person;
//	}
//
//	public void setPerson(Person person) {
//		this.person = person;
//	}

	@Column(name = "Account_No", nullable = false, length = 60)
	public String getAccountNo() {
		return this.accountNo;
	}

	public void setAccountNo(String accountNo) {
		this.accountNo = accountNo;
	}

	@Column(name = "Person_Name", nullable = false, length = 60)
	public String getPersonName() {
		return this.personName;
	}

	public void setPersonName(String personName) {
		this.personName = personName;
	}

	@Column(name = "Password", nullable = false, length = 32)
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "User_category", nullable = false, precision = 8, scale = 0)
	public Long getUserCategory() {
		return userCategory;
	}

	public void setUserCategory(Long userCategory) {
		this.userCategory = userCategory;
	}

}